package io.sage.modules.goods.enums;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public enum GoodsStatusEnum {
    APPLY(2, "已申请"),
    LEND(1, "已借出"),
    NORMAL(0, "正常"),
    WAITCHECK(3, "待检"),//借出之后检测到，修改为当前状态
    BAD(4, "已损坏");//

    private Integer code;
    private String message;


    /**
     * 根据code获取message
     * @param code
     * @return
     */
    public static String getMessage(Integer code){
        for (GoodsStatusEnum examEnum : GoodsStatusEnum.values()){
            if (code.equals(examEnum.getCode()) || code == examEnum.getCode()){
                return examEnum.getMessage();
            }
        }
        return null;
    }

    public static List<Map<String, Object>> getList() {
        List<Map<String, Object>> returnList = new ArrayList<Map<String, Object>>();
        GoodsStatusEnum[] values = GoodsStatusEnum.values();
        for (GoodsStatusEnum questionGradeEnum : values) {
            HashMap<String, Object> hashMap = new HashMap<String, Object>();
            hashMap.put("code", questionGradeEnum.getCode());
            hashMap.put("message", questionGradeEnum.getMessage());
            returnList.add(hashMap);
        }
        return returnList;
    }

    private GoodsStatusEnum(Integer code, String message) {
        this.code = code;
        this.message = message;
    }
    public Integer getCode() {
        return code;
    }
    public void setCode(Integer code) {
        this.code = code;
    }
    public String getMessage() {
        return message;
    }
    public void setMessage(String message) {
        this.message = message;
    }

}
